package com.liuqianfei.markdown;

import java.util.List;

/**
 * 多行代码块处理器。
 * 
 */
public class CodeBlockEmitter implements BlockEmitter
{

    @Override
    public void emitBlock(StringBuilder out, List<String> lines, String meta)
    {
        out.append("<pre><code");
        if (null != meta && meta.length() > 0)
        {
            out.append(" class=\"" + meta + "\"");
        }
        out.append(">");
        for (final String s : lines)
        {
            for (int i = 0; i < s.length(); i++)
            {
                final char c = s.charAt(i);
                switch (c)
                {
                    case '&':
                        out.append("&amp;");
                        break;
                    case '<':
                        out.append("&lt;");
                        break;
                    case '>':
                        out.append("&gt;");
                        break;
                    default:
                        out.append(c);
                        break;
                }
            }
            out.append('\n');
        }
        out.append("</code></pre>\n");
    }

}
